#include <iostream>
#include <string>
#include <fstream>
#include <cassert>
#include "../includes/json.h"
#include "../includes/libbus.h"

using namespace std;



bool readFromFile(string filename)
{
    ifstream file;
    file.open(filename);
    if(!file.is_open()) 
        return false;
    Json::Reader reader;
    Json::Value root;
    if (!reader.parse(file, root, false))
    {
        cerr << "parse failed \n";
        return false;
    }
    cout<<root.size()<<endl;
    Json::Value line = root["1"];
    Json::Value start_t = line["始发时间"].asString();
    Json::Value end_t = line["结束时间"].asString();
    cout<<"始发时间"<<start_t<<endl;
    const Json::Value& stations = line["站点表"];
    for(const auto& station : stations)
    {
        const Json::Value& station_name = station["站名"].asString();
        const Json::Value& station_id = station["序号"].asInt();
        const Json::Value& next_time = station["下一站间隔"].asInt();
        const Json::Value& is_ex_station = station["换乘"].asBool();
        cout<<"站名"<<station_name<<endl;
        cout<<"序号"<<station_id<<endl;
        cout<<"下一站间隔"<<next_time<<endl;
        cout<<"换乘"<<is_ex_station<<endl;
        cout<<endl;
    }
    return true;
}

int main(int argc, char** argv)
{
    if(!readFromFile("../data/station.json"))
        cerr<<"read failed"<<endl;
    return 0;
}
